import 'package:core_package/core_package.dart';
import 'package:flutter_app_unionad/core/withdraw_deposit_manager/contract_info_model.dart';
import 'package:flutter_app_unionad/request/base_request.dart';

import 'h5_generate_contract_model.dart';

class WithdrawDepositRequest {
  ///检查是否可以提现
  static Future<ContractInfoModel?> getContractInfo({
    int type = 0, // 0 推广， 1合伙人
  }) async {
    final future = await HttpRequest.getRequest('/api/lingXinPay/checkIncomeCash', params: {"type": type});
    ContractInfoModel? model;
    baseRequestAnalysisData(future, (map) {
      model = ContractInfoModel.fromJson(map);
    }, (info, code) {});
    return model;
  }

//签合约
  static Future<H5GenerateContractModel?> getH5GenerateContract() async {
    final future = await HttpRequest.getRequest('/api/lingXinPay/h5GenerateContract');
    H5GenerateContractModel? model;
    baseRequestAnalysisData(future, (map) {
      model = H5GenerateContractModel.fromJson(map);
    }, (info, code) {});
    return model;
  }

  //保存银行卡
  static Future<bool> saveBankInfo({
    String? bankCardNumber, //银行卡
    String? documentNumber, //证件号
    int? documentType, //证件类型：0.身份证 1.台湾通行证 2港澳台通行证
    String? telNumber, //预留手机号
    String? userName, //用户名称
  }) async {
    Map<String, dynamic> map = {
      'bankCardNumber': bankCardNumber,
      'documentNumber': documentNumber,
      'documentType': documentType,
      'telNumber': telNumber,
      'userName': userName,
    };
    final future = await HttpRequest.postRequest('/api/lingXinPay/saveBankInfo', params: map);
    bool result = false;
    baseRequestAnalysisData(future, (data) {
      result = true;
    }, (info, code) {
      ShowToastWidget.showToast(msg: info);
    });
    return result;
  }

//合伙人提现
  static Future<bool> withdrawDeposit({
    num? amount,
    int? type, // 0 推广人 1合伙人
  }) async {
    final future = await HttpRequest.postRequest(
        type == 0 ? '/api/lingXinPay/pointCash' : '/api/lingXinPay/bpotopTradeSingle',
        params: {'amount': amount});
    bool result = false;
    baseRequestAnalysisData(future, (data) {
      result = true;
    }, (info, code) {
      ShowToastWidget.showToast(msg: info);
    });
    return result;
  }
}
